<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('邮件列表')" />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>邮件列表</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/iCheck/custom.css}" rel="stylesheet">
    <link th:href="@{/css/animate.css}" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <link th:href="#{/css/iCheck/custom.css}" rel="stylesheet">
    <style type="text/css">
        #bootstrap-table {border-left: 0px; border-right:0px}
        #bootstrap-table th{border-left: 0px; border-right: 0px}
        #bootstrap-table td{border-left: 0px; border-right: 0px}
    </style>
</head>

<body>

<div id="wrapper">
    <div class="wrapper wrapper-content gray-bg">
        <div class="row">
            <div class="col-lg-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-content mailbox-content">
                        <div class="file-manager">
                            <a class="btn btn-block btn-primary compose-mail"href="javascript:void(0)" onclick="toSendEmail()">写邮件</a>
                            <div class="space-25"></div>
                            <h3>邮件标签</h3>
                            <ul class="category-list" style="padding: 0">
                                <li><a href="#"> <i class="fa fa-circle text-navy"></i> 工作 </a></li>
                                <li><a href="#"> <i class="fa fa-circle text-danger"></i> 文档</a></li>
                                <li><a href="#"> <i class="fa fa-circle text-primary"></i> 社交</a></li>
                                <li><a href="#"> <i class="fa fa-circle text-info"></i> 活动</a></li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-9 animated fadeInRight">
                <div class="mail-box-header">
                    <form  class="pull-right mail-search select-list" id="formId">
                        <div class="input-group">
                            <input type="hidden" name="mailSearchType" th:value="${mailType}" id="mailType" >
                            <input type="text" class="form-control input-sm" name="emailSubject"  placeholder="Search email">
                            <div class="input-group-btn">
                                <a onclick="$.table.search()" class="btn btn-sm btn-primary">
                                    请输入邮件主题
                                </a>
                            </div>
                        </div>
                    </form>
                    <h2>
                        DingFlow发件箱
                    </h2>

                </div>
                <div class="ibox-content">
                    <table id="bootstrap-table" class="col-sm-12 select-table table-striped"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Mainly scripts -->
<script th:src="@{/js/jquery.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ajax/libs/layui/layui.js}"></script>
<script th:src="@{/ruoyi/js/common.js}"></script>
<script th:src="@{/ruoyi/js/ry-ui.js}"></script>
<script th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js?v=20200727}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js?v=20200727}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js?v=20200727}"></script>
<script th:inline="javascript">
    var prefix =  "/system/email";
    var emailLabelDatas = [[${@dict.getType('sys_email_lable')}]];
    $(document).ready(function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $.get(prefix+"/getSysOaEmailData", function(data) {
            if (data.code == web_status.SUCCESS ) {
                var sysOaEmailData=data.data;
                $("#readTotal").text(sysOaEmailData.readTotal);
                $("#draftsTotal").text(sysOaEmailData.draftsTotal);
            }  else if (data.code == web_status.WARNING) {
                $.modal.alertWarning(data.msg)
            }  else {
                $.modal.alertError(data.msg);
            }
        });
    });

    var options = {
        url: prefix + "/getSendMail",
        rememberSelected: true,
        modalName: "邮件",
        showToggle:false,
        showHeader:true,
        showSearch:false,
        showRefresh:false,
        showColumns:false,
        queryParams: queryParams,
        striped:true,
        loadingFontSize:20,
        height:'30px',
        columns: [
            {
                field: 'id',
                title: 'id',
                visible: false
            },

            {
                field: 'emailSubject',
                title: '邮件主题',
                align:'left',
                formatter: function(value, row, index) {
                    var emailStatus= row.emailStatus;
                    if(emailStatus==3){
                        return '<i class="fa fa-flag danger" style="color: red"></i> '+'<a href="javascript:void(0)" onclick="mailDetail(\''+row.id+'\')">'+value+'</a> ';
                    }else {
                        return '<a href="javascript:void(0)" onclick="mailDetail(\''+row.id+'\')">'+value+'</a> ';
                    }
                }
            },
            {
                field: 'producerUser.email',
                title: '收件邮箱',
                align:'left'
            },
            {
                field: 'emailLabel',
                title: '邮件标签',
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(emailLabelDatas, value);
                }
            },
            {
                field: 'sendTime',
                title: '发送时间',
                width: 220,
                align: 'right'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                        if(row.emailStatus!=3){
                            actions.push('<button class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="标记为重要邮件" onclick="remarkImportant(\''+row.id+'\')"><i class="fa fa-flag"></i> </button> ');
                        }
                        actions.push('<button class="btn btn-warning btn-sm" data-toggle="tooltip" data-placement="top" title="移到垃圾箱" onclick="remarkTrash(\''+row.id+'\')"><i class="fa fa-trash"></i> </button> ');
                        actions.push('<button class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="删除" onclick="markDelete(\''+row.id+'\')"><i class="fa fa-remove"></i> </button> ');
                    return actions.join('');
                }
            }
        ]
    };
    $.table.init(options);
    function queryParams(params) {
        var search = $.table.queryParams(params);
        return search;
    }

    function remarkImportant(id){
        /*  var arrays = $.table.selectColumns("id");
          if($.common.isEmpty(arrays)){
              $.modal.msgWarning("请至少选择一条记录");
              return false;
          }*/
        var config = {
            url: prefix + "/remarkImportant",
            type: "post",
            dataType: "json",
            data: {
                "ids":id
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
                $.modal.disable();
            },
            success: function(result) {
                if (typeof callback == "function") {
                    callback(result);
                }
                if (result.code == web_status.SUCCESS) {
                    $.modal.msg("标记成功，即将跳转到重要邮件箱", modal_status.SUCCESS);
                    setTimeout(function(){
                       // window.location.href="/system/email/importantMail";
                        $.modal.openTab("标星邮件", "/system/email/importantMail");
                    },3000);
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                }  else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
                $.modal.enable();
            }
        };
        $.ajax(config)
    }

    function remarkTrash(id){
        var config = {
            url: prefix + "/remarkTrash",
            type: "post",
            dataType: "json",
            data: {
                "ids":id
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
                $.modal.disable();
            },
            success: function(result) {
                if (typeof callback == "function") {
                    callback(result);
                }
                if (result.code == web_status.SUCCESS) {
                    $.modal.msg("标记成功，即将跳转到垃圾箱", modal_status.SUCCESS);
                    setTimeout(function(){
                       // window.location.href="/system/email/trashMail";
                        $.modal.openTab("垃圾箱", "/system/email/trashMail");
                    },3000);
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                }  else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
                $.modal.enable();
            }
        };
        $.ajax(config);
    }

    function markDelete(id){
        var config = {
            url: prefix + "/markDelete",
            type: "post",
            dataType: "json",
            data: {
                "ids":id
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
                $.modal.disable();
            },
            success: function(result) {
                if (typeof callback == "function") {
                    callback(result);
                }
                if (result.code == web_status.SUCCESS) {
                    $.modal.msg("删除成功，即将跳转到收件箱", modal_status.SUCCESS);
                    setTimeout(function(){
                        window.location.href="/system/email/sendMail";
                       // $.modal.openTab("标星邮件", "/system/email/sendMail");
                    },3000);
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                }  else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
                $.modal.enable();
            }
        };
        $.ajax(config)
    }

    function mailDetail(id) {
        var detailUrl="/system/email/mailDetail/"+id;
        $.modal.openTab("查阅邮件", detailUrl);
    }
    function toSendEmail() {
        $.modal.openTab('邮件管理',  prefix);
    }
</script>
</body>

</html>
